/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Pages;

import Rout.ChromeProfile;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.yaml.snakeyaml.tokens.Token;

/**
 *
 * @author user
 */
public class Page {

    public WebElement element;
    public String id, cl, cs, xpa;
    public String string;

    public WebElement getElement(WebDriver driver, String param, String pageURL, String idelement, String classname, String css, String xpath) throws Exception {                       
        
        this.id = idelement;
        this.cl = classname;
        this.cs = css;
        this.xpa = xpath;      
        driver.get(pageURL);
        Thread.sleep(1000);
        Actions clicker = new Actions(driver);
        clicker.sendKeys(Keys.PAGE_DOWN).perform();
        clicker.sendKeys(Keys.PAGE_DOWN).perform();
        
        try {
            try {
                System.out.println("try 1" + id);
                element = (driver.findElement(By.id(id)));                
            } catch (Exception e1) {
                try {
                    System.out.println("try 2" + cs);
                    element = (driver.findElement(By.cssSelector(cs)));                    
                } catch (Exception e2) {
                    try {
                        System.out.println("try 3" + xpa);
                        element = driver.findElement(By.xpath(xpa)); 
                    } catch (Exception e) {
                        System.out.println("No search element");
                    }                                                                                                        
                }
            }            
        } catch (Exception e) {
            System.out.println("ERROR: " + e.getMessage() + "\n");
        }
        
        string = element.getText();
        System.out.println(param + ": " + string);
        return element;
    }       

}
